var app = getApp();
Page({
  data:{
    ischeck : false,
    page : {
        isend : false,
        doing : false,
        doo : 'lookform',
        pdata : {
            op : 'list',
            page : 1,
            password : '',
            type : 1,
        },
        waitf : 0,
        nodataf : 0,
    },
    datalist : [],
    actdata : [],
    showinfo : false,
  },
    onLoad:function(options){
        var that = this;
    },
    onReady:function(){
        // 页面渲染完成
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: '查看表单数据',
            path: '',
        }
    },
    look : function(e){
        var self = this;

        if( self.data.page.pdata.password == '' ){
            app.util.message('请输入验证码','','error');
            return false;
        }

        app.com.getPage(self,self.data.page,20,function(res){

            self.setData({
               datalist : res.data.data,
               ischeck : true,
            });
        },false,function(res){
            
            app.util.message(res.data.message,'','error');
        });
    },
    setPass : function(e){
        var self = this;
        self.setData({
            'page.pdata.password' : e.detail.value,
        });
    },
    onReachBottom : function(){
        var self = this;

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data)
            });
        });
    },
    showform : function(e){
        var self = this;
        var id = e.currentTarget.dataset.id;

        for(var t in self.data.datalist ) {
            if( self.data.datalist[t].id == id ) {
                
                var arr = [];
                for (var i in self.data.datalist[t].data ) {
                    arr.push( {name : i , value : self.data.datalist[t].data[i]} );
                }

                self.setData({
                    actdata : arr,
                    actinfo : self.data.datalist[t],
                    showinfo : true
                });

            }
        }
    },
    closesheet : function(){
        var self = this;
        self.setData({
            showinfo : false
        });
    },
    changetype : function(e){
        var self = this;
        self.setData({
            'page.pdata.type' : e.currentTarget.dataset.type,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data
            });
        });
    },
    readit : function( e ){
        var self = this;
        var id = e.currentTarget.dataset.id;
        app.com.http('lookform','POST',{id:id,password : self.data.page.pdata.password,op:'readit'},0,true,function(res){
            if (!res.data.errno) {
                for (var i = 0; i < self.data.datalist.length; i++) {
                    if( self.data.datalist[i].id == id ) {
                        self.data.datalist.splice(i,1);
                    }
                }
                self.setData({
                    showinfo : false,
                    'datalist' : self.data.datalist
                });
                wx.showToast({
                  title: '完成',
                  icon: 'success',
                  duration: 1000
                });
            }
        })
    }

})